import requests


class TpLogin(object):
    """前台登录类"""
    base_url = "http://hmshop-test.itheima.net"  # 类属性

    def __init__(self):
        """设置实例属性"""
        self.login_url = TpLogin.base_url + "/index.php?m=Home&c=User&a=do_login"

    def login(self, username, password, verify_code):
        """登录前台页面"""
        header = {"Content-Type": "application/x-www-form-urlencoded"}
        test_data = {"username": username, "password": password, "verify_code": verify_code}
        return requests.post(self.login_url, json=test_data, headers=header)


if __name__ == '__main__':
    # 创建对象
    login_api = TpLogin()
    # 调用login方法:登录成功
    login_api.login("13800000001", "123456", 8888)
